// 数组类型

import java.util.Arrays;

public class Demo04 {
    public static void main(String[] args) {
        int[] ns = new int[5];
        ns[0] = 1;
        ns[1] = 2;
        ns[2] = 3;
        ns[3] = 400;
        ns[4] = 500;
        int n = 4;
        System.out.println(ns[n]);
        System.out.println(Arrays.toString(ns));

        // 直接初始化元素
        int[] ns2 = new int[] { 1, 2, 3, 4, 5 };
        // 还可以简写为
        int[] ns3 = { 4, 5, 6, 7, 8 };
        System.out.println(Arrays.toString(ns2));
        System.out.println(Arrays.toString(ns3));

        int[] ns4 = { 1, 2, 3, 4, 5 };
        ns4[3] = 100;
        System.out.println(Arrays.toString(ns4));

        String[] ss = new String[] { "张三", "李四" };
        ss[0] = "王五";
        System.out.println(Arrays.toString(ss));

        String[] names = { "ABC", "XYZ", "zoo" };
        String s = names[1];
        names[1] = "cat";
        System.out.println(s); // s是"XYZ"还是"cat"?
    }
}
